<%@page import="com.mavenrentcars.model.Role"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.List"%>
<%@page import="com.mavenrentcars.form.AccountForm"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/header.jsp" %>

<% 
	AccountForm form = (AccountForm) request.getAttribute("item");
    List<Role> roles = (List<Role>) request.getAttribute("roles");
    String json_roles = (String) request.getAttribute("json_roles");
%>

    <h1>Account</h1>
    <div>
        <table border="0">
            <tbody>
                <tr>
                    <td>
                        <div id="account_form">
                            <input type="hidden" id="account_form_action" value="<%=form.action %>" />
                            <input type="hidden" id="account_form_id" value="<%=form.id %>" />
                            <table border="0">
                                <tbody>
                                    <tr>
                                        <td>Email:</td>
                                        <td><input type="text" id="account_form_email" value="<%=form.email %>" /></td>
                                    </tr>
                                    <tr>
                                        <td>Name:</td>
                                        <td><input type="text" id="account_form_name" value="<%=form.name %>" /></td>
                                    </tr>
                                                        <tr>
                                        <td>Phone:</td>
                                        <td><input type="text" id="account_form_phone" value="<%=form.phone %>" /></td>
                                    </tr>
                                    <tr>
                                        <td>Address:</td>
                                        <td><input type="text" id="account_form_address" value="<%=form.address %> " /></td>
                                    </tr>
                                    <tr>
                                        <td>Gender:</td>
                                        <td><input type="text" id="account_form_gender" value="<%=form.gender %>" /></td>
                                    </tr>
                                    <tr>
                                        <td>Drive length:</td>
                                        <td><input type="text" id="account_form_drive_length" value="<%=form.drive_length %>" /></td>
                                    </tr>
                                    <tr>
                                        <td>Drive category:</td>
                                        <td><input type="text" id="account_form_drive_category" value="<%=form.drive_category %>" /></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <div id="roles_list"></div>
                                        </td>    
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <input type="submit" id="account_save_action" value="Send" />
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </td>
                    <td style="vertical-align: top;">
                        <div  id="roles_list">
                            <table border="0">
                            <tbody>
                                <tr>
                                    <td colspan="2">Roles:</td>
                                </tr>
                                <%
                                for(Role ritem : roles) {
                                %>
                                <tr>
                                    <td><%= ritem.getRoleName() %></td>
                                    <td>
                                        <div class="link role_action" id="role_action_<%= ritem.getId() %>"><%=((form.roles.get(Integer.toString(ritem.getId())) != null) ? "delete" : "add")%></div>
                                    </td>
                                </tr>
                                <% } %>
                            </tbody>
                            </table>
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
		
		
	<script type="text/javascript">
		
		$(document).ready(function(){
                    var accountModel = new AccountModel(<%=json_roles%>);
                    var accountView = new AccountView();
                    var accountController = new AccountController(accountModel, accountView);
                    accountController.init();
		});
	</script>
    
<%@ include file="/WEB-INF/jsp/footer.jsp" %>